package com.ly.gateway.fifter;

import com.alibaba.fastjson.JSON;
import com.common.core.domain.AjaxResult;
import com.common.core.domain.R;
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.io.buffer.DataBuffer;
import org.springframework.core.io.buffer.DataBufferFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;


//如果想要控制子过滤器干点啥可以自定义抽象方法
//GlobalFilter：全局过滤器 这是每个接口必须走的过滤器 配置多个全局过滤器就走多个
public abstract class AbstractGatewayFilter implements GlobalFilter {


    /**
     * 是否要过滤 开关逻辑 对应的子业务过滤器是否执行
     */
    abstract boolean should(ServerWebExchange exchange);


    /**
     * 执行
     */
    abstract Mono<Void> doFilter(ServerWebExchange exchange, GatewayFilterChain chain);


    @Override
    public final Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        if (should(exchange)) {
            return doFilter(exchange, chain);
        } else {
            return chain.filter(exchange);
        }
    }







}
